﻿#ifndef SALEQUERYSTANDARDITEMMODEL_H
#define SALEQUERYSTANDARDITEMMODEL_H

#include <QStandardItemModel>
#include "userrelation.h"
#include "dingdan.h"
#include "dingdananddetail.h"

class SaleQueryStandardItemModel : public QStandardItemModel
{
    Q_OBJECT
public:
    enum WidgetType{
        Sale=1,
        Purchase=2,
        Profit=3
    };

    Q_ENUM(WidgetType)
    explicit SaleQueryStandardItemModel(QObject *parent = nullptr);

    QVariant data(const QModelIndex &index, int role) const override;

    QStringList headerDingdan;  //按订单时表头
    QStringList headerDetail;   //按明细时表头

    void setWidgetType(WidgetType widgetType);

    void setType(int type);

    void reset();

    void insertDingdan(Dingdan &dingdan);

    void insertDingdan(QList<Dingdan*> dingdans);

    void insertDingdanDetail(DingdanAndDetail &detail);

    void insertDingdanDetail(QList<DingdanAndDetail*> details);

    void refreshTotalProfit();
    /**
     * @brief refreshTotalValue 刷新合计金额、票款、货款
     */
    void refreshTotalValue();

    QString getDingdanId(int index);

signals:
    void updateTotalProfit(double totalProfit, double averageProfit);
    /**
     * @brief updateTotalValue
     * @param totalValue 合计金额
     * @param totalTicket 合计票款
     * @param totalMoney 合计货款
     */
    void updateTotalValue(double totalValue, double totalTicket, double totalMoney);

public slots:

private:
    WidgetType widgetType;

    QList<Dingdan*> dingdans;
    QList<DingdanAndDetail*> details;

    QStringList header;
    int type;
};

#endif // SALEQUERYSTANDARDITEMMODEL_H
